<?php
namespace Admin\Controller;

use Common\Base\ControllerBase;

class DatabaseController extends ControllerBase
{
    public function index()
    {
        $list = M()->query('SHOW TABLE STATUS');
        $this->assign('list', $list);
        $this->display();
    }

    public function optimize()
    {
        $table = I('get.table', '');
        if($table == ''){ $this->error("请指定要优化的表！"); }
        $list = M()->execute("OPTIMIZE TABLE `'".$table."`");
        if($list){
            $this->success("数据表'".$table."'优化完成！", U('database/index'));
        }else{
            $this->error("数据表'".$table."'优化出错请重试！", U('database/index'));
        }
    }

    public function repair()
    {
        $table = I('get.table', '');
        if($table == ''){ $this->error("请指定要修复的表！"); }
        $list = M()->execute("REPAIR TABLE `".$table."`");
        if($list){
            $this->success("数据表'".$table."'修复完成！", U('database/index'));
        }else{
            $this->error("数据表'".$table."'修复出错请重试！", U('database/index'));
        }
    }
}